<extend name="Public/base" />
<block name="main">
    <fieldset class="layui-elem-field">
        <legend>菜单管理 - 菜单列表</legend>
        <div class="layui-field-box">
            <span class="layui-btn layui-btn-normal api-add"><i class="layui-icon">&#xe608;</i> 新增</span>
            <table class="layui-table" lay-even>
                <thead>
                <tr>
                    <th>#</th>
                    <th>菜单名称</th>
                    <th>排序</th>
                    <th>菜单URL</th>
                    <th>隐藏</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <volist name="list" id="vo">
                    <tr>
                        <td>{$i}</td>
                        <td>{$vo['showName']}</td>
                        <td>{$vo['sort']}</td>
                        <td>{$vo['url']}</td>
                        <td>
                            <if condition="$vo['hide']">
                                <span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">隐藏</span>
                                <else />
                                <span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">显示</span>
                            </if>
                        </td>
                        <td>
                            <if condition="$vo['hide']">
                                <span class="layui-btn confirm" data-info="你确定显示当前菜单么？" data-id="{$vo['id']}" data-url="{:U('open')}">显示</span>
                                <else />
                                <span class="layui-btn layui-btn-danger confirm" data-info="你确定隐藏当前菜单么？" data-id="{$vo['id']}" data-url="{:U('close')}">隐藏</span>
                            </if>
                            <span data-url="{:U('edit', array('id' => $vo['id']))}" class="layui-btn edit layui-btn-normal">编辑</span>
                            <span class="layui-btn layui-btn-danger confirm" data-id="{$vo['id']}" data-info="你确定删除当前菜单么？" data-url="{:U('del')}">删除</span>
                        </td>
                    </tr>
                </volist>
                </tbody>
            </table>
        </div>
    </fieldset>
</block>
<block name="myScript">
    <script>
        layui.use(['layer'], function() {
            $('.api-add').on('click', function () {
                layer.open({
                    type: 2,
                    area: ['80%', '80%'],
                    maxmin: true,
                    content: '{:U("add")}'
                });
            });
            $('.edit').on('click', function () {
                var ownObj = $(this);
                layer.open({
                    type: 2,
                    area: ['80%', '80%'],
                    maxmin: true,
                    content: ownObj.attr('data-url')
                });
            });
            $('.confirm').on('click', function () {
                var ownObj = $(this);
                layer.confirm(ownObj.attr('data-info'), {
                    btn: ['确定','取消'] //按钮
                }, function(){
                    $.ajax({
                        type: "POST",
                        url: ownObj.attr('data-url'),
                        data: {id:ownObj.attr('data-id')},
                        success: function(msg){
                            if( msg.code == 1 ){
                                location.reload();
                            }else{
                                layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                });
            });
        });
    </script>
</block>